<?php
/**
 * Created by PhpStorm.
 * User: Guangpen Chen
 * Date: 2014-11-29
 * Time: 13:54
 */
if (!isset($redis)) {
    $redis = new Redis();
    $redis->connect('10.169.9.198', 6379);
    $redis->auth('myPft!12301!&');
}
//二级域名处理
//step1:获取供应商账号，再获取id
$host = str_replace('www.', '', $_SERVER['HTTP_HOST']);
$applyAccount = substr($host, 0, strpos($host, '12301')-1);

$redis_key = "shop_{$applyAccount}";

$shop = $redis->get($redis_key);
//var_dump($shop);
if (!$shop) {
    //step2:根据账号查询该供应商二级域名的配置
    $sql = <<<SQL
SELECT `fid`,`M_domain`, `M_name`, `M_logo1`, `M_logo2`, `M_banner`,
`M_banner_url`, `M_navi`, `M_qq`, `M_tel`, `M_host`
FROM pft_member_domain_info WHERE M_domain='{$applyAccount}' LIMIT 1
SQL;
    $GLOBALS['le']->query($sql);
    $shop = $GLOBALS['le']->fetch_assoc();
    if ($shop) {
        $redis->setex($redis_key, 1800, serialize($shop));
    }
    else {
        exit('404');
    }
}
else {
    $shop = unserialize($shop);
}
//var_dump($shop);
//print_r($shop);
//exit;

